/******************************************/
/**			harddisk.h by doom119		  */
/**				June, 2010				  */
/******************************************/
#ifndef _HARDDISK_H_
#define _HARDDISK_H_

/* hard disk controller registers */
#define HD_DATA			0x1f0	
#define HD_ERROR		0x1f1
#define HD_NSECTOR		0x1f2	// nr of sectors to read/write
#define HD_SECTOR		0x1f3	// starting sector
#define HD_LCYL 		0x1f4 	// low byte of starting cylinder
#define HD_HCYL			0x1f5	// high byte of starting cylinder
#define HD_CURRENT		0x1f6	// 101 dhhhh, d=drive, hhhh=head
#define HD_STATUS		0x1f7	
#define HD_PRECOMP		HD_ERROR
#define HD_COMMAND		HD_STATUS

#define HD_CMD 			0x3f6

/* bits of HD_STATUS */
#define ERR_STAT		0x01
#define INDEX_STAT		0x02
#define ECC_STAT		0x04
#define DRQ_STAT		0x08
#define SEEK_STAT		0x10
#define WRERR_STAT		0x20
#define READY_STAT		0x40
#define BUSY_STAT		0x80

/* values for HD_COMMAND */
#define WIN_RESTORE		0x10
#define WIN_READ		0x20
#define WIN_WRITE		0x30
#define WIN_VERIFY 		0x40
#define WIN_FORMAT		0x50
#define WIN_INIT		0x60
#define WIN_SEEK		0x70
#define WIN_DEAGNOSE	0x90
#define WIN_SPECIFY		0x91

/* bits for HD_ERROR */
#define MARK_ERR		0x01
#define TRK0_ERR		0x02
#define ABRT_ERR		0x04
#define ID_ERR			0x10
#define ECC_ERR			0x40
#define BBD_ERR			0x80

struct hd_info
{
	short cyl; //(00h)number of cylinders
	char head; //(02h)number of heads
	short xt; //(03h)starting reduced write current cylinder(XT only, 0 for others)
	short wpcom; //(05h)starting write precompensation cylinder number
	char ecc; //(07h)maximum ECC burst length(XT only)
	char control; //(08h)control byte
	char s_timeout; //(09h)standard timeout
	char f_timeout; //(0Ah)formatting timeout(XT and WD1002 only, 0 for others)
	char c_timeout; //(0Bh)timeout for checking drive(XT and WD1002only, 0 for others)
	short lzone; //(0Ch)cylinder number of landing zone(AT and later only)
	char sect; //(0Eh)number of sectors per track(AT and later only)
	char reserved; //(0Fh)reserved
};

struct hd_partition
{
	unsigned long start_sector;
	unsigned long nr_sectors;
};

struct partition
{
	unsigned char boot_ind;
	unsigned char head;
	unsigned char sector;
	unsigned char cyl;
	unsigned char sys_ind;
	unsigned char end_head;
	unsigned char end_sector;
	unsigned char end_cyl;
	unsigned long start_sect;
	unsigned long nr_sects;
};

#endif
